package com.gxa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.mapper.RoleMapper;
import com.gxa.param.NoticeParam;
import com.gxa.pojo.Role;
import com.gxa.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {


    @Autowired
    private RoleMapper mapper;



    @Override
    public LayR list(NoticeParam param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<Role> roles = mapper.findAll(param);
        PageInfo<Role> pageInfo = new PageInfo<>(roles);
        List<Role>list = pageInfo.getList();
        for(Role role:list){
            System.out.println(role);
        }
        return new LayR(0, "success", pageInfo.getTotal(), pageInfo.getList());
    }



    @Override
    public R add(Role role) {
        role.setRoleName(role.getRoleName());
        role.setRoleDesc(role.getRoleDesc());
        return new R(200,"success") ;
    }

    @Override
    public R deleteAll(String[] ids) {
        mapper.deleteAll(ids);
        return new R(200, "删除成功！");
    }

    @Override
    public R deleteid(Integer role_id) {
        mapper.deleteid(role_id);
        return new R(200,"success");
    }
}
